package com.geovis.emergency.spd.biz.system.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geovis.emergency.spd.biz.system.mapper.SystemDictDataMapper;
import com.geovis.emergency.spd.biz.system.service.ISystemDictDataService;
import com.geovis.emergency.spd.entity.system.constant.SystemCacheConstant;
import com.geovis.emergency.spd.entity.system.entity.SystemDictData;
import com.geovis.emergency.spd.entity.system.pojo.vo.DictVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 字典数据表 服务实现类
 * </p>
 *
 * @author 王响
 * @since 2020-08-25
 */
@Service
@AllArgsConstructor
@Slf4j
public class SystemDictDataServiceImpl extends ServiceImpl<SystemDictDataMapper, SystemDictData> implements ISystemDictDataService {
    @Override
    @Cacheable(value = SystemCacheConstant.SYSTEM_DICT_DATA_TREE,key = "#dictCode",unless = "#result?.size() == 0")
    public List<DictVO> dictTreeList(String dictCode) {

        return baseMapper.dictTreeList(dictCode);
    }

    @Override
    public List<DictVO> dictTreeAllList(String dictId) {
        return baseMapper.dictTreeAllList(dictId);
    }

    @Override
    @Cacheable(value = SystemCacheConstant.SYSTEM_DICT_DATA,key = "T(String).valueOf(#dictCode).concat(':').concat(#dataKey)",unless = "#result=null")
    public String getDictValue(String dictCode, String dataKey) {
        return baseMapper.getValue(dictCode,dataKey);
    }

    @Override
    @Cacheable(value = SystemCacheConstant.SYSTEM_DICT_DATA_LIST,key = "#dictCode",unless = "#result?.size() == 0")
    public List<SystemDictData> getDictData(String dictCode) {
        return baseMapper.getList(dictCode);
    }
}
